home *** CD-ROM | disk | FTP | other *** search
/ CD Classic / CD CLASSIC #1.iso / 3df / 3df.asm next >
Assembly Source File  |  1991-04-18  |  11KB  |  403 lines

  1. page 66,132
  2. ;
  3. ; Assembly Language Support for fast3d
  4. ; in Turbo Pascal 5.0.  Gene Ressler
  5. ;
  6.                 .MODEL TPASCAL
  7.  
  8. N_PIX_X         equ     640
  9. N_PIX_Y         equ     192
  10. BUF_SIZE        equ     16384
  11.  
  12.                 .DATA
  13.                 ALIGN 2
  14. x0              dw      ?
  15. y0              dw      ?
  16. oldVec          dw      N_PIX_X dup (?)
  17. newVec          dw      N_PIX_X dup (?)
  18. minUpdtPtr      dw      ?
  19. maxUpdtPtr      dw      ?
  20. scrBuf          db      BUF_SIZE dup (?)
  21.  
  22.                 .CODE
  23. VIDEO           equ     10h
  24. SELECT_MODE     equ      0
  25. PALLETTE        equ     11
  26. SET_BACKGROUND  equ      0
  27. SET_PALLETTE    equ      1
  28. SCREEN_SEG      equ     0B800h
  29.  
  30. SetVideo        PROC NEAR mode: BYTE
  31.                 PUBLIC SetVideo
  32.                 mov     ah, SELECT_MODE
  33.                 mov     al, mode
  34.                 int     VIDEO
  35.                 ret
  36. SetVideo        ENDP
  37.  
  38. SetPallette     PROC NEAR pal: BYTE
  39.                 PUBLIC SetPallette
  40.                 mov     ah, PALLETTE
  41.                 mov     bh, SET_PALLETTE
  42.                 mov     bl, pal
  43.                 and     bl, SET_PALLETTE
  44.                 int     VIDEO
  45.                 ret
  46. SetPallette     ENDP
  47.  
  48. SetBackground   PROC NEAR pal: BYTE
  49.                 PUBLIC SetBackground
  50.                 mov     ah, PALLETTE
  51.                 mov     bh, SET_BACKGROUND
  52.                 mov     bl, pal
  53.                 and     bl, 0Fh
  54.                 int     VIDEO
  55.                 ret
  56. SetBackground   ENDP
  57.  
  58. ClearScreen     PROC NEAR
  59.                 PUBLIC ClearScreen
  60.                 mov    ax, SCREEN_SEG
  61.                 mov    es, ax
  62.                 xor    ax, ax
  63.                 xor    di, di
  64.                 mov    cx, BUF_SIZE/2
  65.                 cld
  66.                 rep stosw
  67.                 ret
  68. ClearScreen     ENDP
  69.  
  70. InitCloud      PROC   NEAR
  71.                PUBLIC InitCloud
  72.                mov    ax, ds
  73.                mov    es, ax
  74.                mov    cx, N_PIX_X
  75.                mov    dx, cx
  76.                mov    ax, -1
  77.                mov    di, offset oldVec
  78.                cld
  79.                rep stosw
  80.                mov    cx, dx
  81.                mov    di, offset newVec
  82.                rep stosw
  83.                mov    minUpdtPtr, offset newVec + 2*(N_PIX_X-1)
  84.                mov    maxUpdtPtr, offset newVec
  85.                ret
  86. InitCloud      ENDP
  87.  
  88. UpdateCloud    PROC NEAR
  89.                PUBLIC UpdateCloud
  90.                mov    si, minUpdtPtr
  91.                mov    cx, maxUpdtPtr
  92.                sub    cx, si
  93.                jb     noUpdateNeeded
  94.                shr    cx, 1
  95.                inc    cx
  96.                mov    di, si
  97.                add    di, offset oldVec - offset newVec
  98.                mov    ax, ds
  99.                mov    es, ax
  100.                cld
  101.                rep movsw
  102.                mov    minUpdtPtr, offset newVec + 2*(N_PIX_X-1)
  103.                mov    maxUpdtPtr, offset newVec
  104.        noUpdateNeeded:
  105.                ret
  106. UpdateCloud    ENDP
  107.  
  108. ClearImage     PROC NEAR
  109.                PUBLIC ClearImage
  110.                mov    ax, ds
  111.                mov    es, ax
  112.                xor    ax, ax
  113.                mov    cx, BUF_SIZE/2
  114.                mov    di, offset scrBuf
  115.                cld
  116.                rep stosw
  117.                ret
  118. ClearImage     ENDP
  119.  
  120. ; Show image buffer on CGA.
  121.  
  122. ShowImage      PROC NEAR
  123.                PUBLIC ShowImage
  124.                mov    ax, SCREEN_SEG
  125.                mov    es, ax
  126.                mov    bx, N_PIX_Y/2
  127.                mov    si, offset scrBuf
  128.                xor    di, di
  129.                mov    dx, 40
  130.                cld
  131.         showLoop:
  132.                mov    cx, dx
  133.                rep movsw          ; Shoot 80 bytes to even buffer.
  134.                add    di, 8192-80
  135.                mov    cx, dx
  136.                rep movsw          ; Now 80 bytes to odd buffer
  137.                sub    di, 8192    ; Get ready for next even buffer row.
  138.                dec    bx
  139.                jnz    showLoop
  140.                ret
  141. ShowImage      ENDP
  142.  
  143. MovePen        PROC NEAR x: word, y: word
  144.                PUBLIC MovePen
  145.                mov ax, x
  146.                mov x0, ax
  147.                mov ax, y
  148.                mov y0, ax
  149.                ret
  150. MovePen        ENDP
  151.  
  152. ;
  153. ; drawLine -- Draw a line from current pen to x, y
  154. ;             and update the current pen.
  155. ;             Consider and update cloud.
  156.  
  157. DrawLine       PROC NEAR x1:word, y1:word
  158.                PUBLIC DrawLine
  159.                LOCAL  c1:word, c2:word, p:word
  160.                LOCAL  newVecPtr:word, oldVecPtr: word
  161.                LOCAL  yInc:word, xInc:word
  162.  
  163.                jmp     overProcs
  164.  
  165.                IFDEF PROFILE
  166.                PUBLIC initX
  167.                PUBLIC initY
  168.                PUBLIC initXinc
  169.                PUBLIC initYinc
  170.                PUBLIC plot
  171.                ENDIF
  172.  
  173. initX          PROC NEAR
  174.                mov     ax, cx
  175.                pop     si
  176.                pop     di
  177.                mov     bx, offset oldVec
  178.                add     bx, di              ; ptr := base+x*2
  179.                add     bx, di
  180.                mov     oldVecPtr, bx
  181.                mov     bx, offset newVec
  182.                add     bx, di
  183.                add     bx, di
  184.                mov     newVecPtr, bx
  185.                mov     cx, di
  186.                shr     di, 1
  187.                shr     di, 1
  188.                shr     di, 1
  189.                add     di, offset scrBuf
  190.                and     cl, 7
  191.                mov     bl, 080h
  192.                shr     bl, cl
  193.                mov     cx, ax
  194.                jmp     si
  195. initX          ENDP
  196.  
  197. initY          PROC NEAR
  198.                pop     si
  199.                pop     ax
  200.                shl     ax, 1
  201.                shl     ax, 1
  202.                shl     ax, 1
  203.                shl     ax, 1
  204.                add     di, ax
  205.                shl     ax, 1
  206.                shl     ax, 1
  207.                add     di, ax
  208.                jmp     si
  209. initY          ENDP
  210.  
  211. initXinc       PROC NEAR
  212.                pop    si
  213.                pop    ax
  214.                pop    dx
  215.                cmp    dx, ax
  216.                jle    negXinc
  217.                mov    xInc, 0
  218.                jmp    si
  219.        negXinc:
  220.                mov    xInc, 1
  221.                jmp    si
  222. initXinc       ENDP
  223.  
  224. initYinc       PROC NEAR
  225.                pop     si
  226.                pop     ax
  227.                pop     dx
  228.                cmp     dx, ax
  229.                jle     negYinc
  230.                mov     yInc, 80
  231.                jmp     si
  232.        negYinc:
  233.                mov     yInc, -80
  234.                jmp     si
  235. initYinc       ENDP
  236.  
  237. plot           PROC NEAR
  238.                push   bx
  239.                mov    bx, newVecPtr
  240.                cmp    di, [bx]
  241.                jae    notNewMin
  242.                mov    [bx], di
  243.  
  244.                cmp    bx, minUpdtPtr
  245.                jae    okOnLeft
  246.                mov    minUpdtPtr, bx
  247.        okOnLeft:
  248.                cmp    bx, maxUpdtPtr
  249.                jbe    okOnRight
  250.                mov    maxUpdtPtr, bx
  251.        okOnRight:
  252.  
  253.        notNewMin:
  254.                mov    bx, oldVecPtr
  255.                cmp    di, [bx]
  256.                pop    bx
  257.                jae    notVis
  258.                or     [di], bl
  259.        notVis:
  260.                ret
  261. plot           ENDP
  262.  
  263.        overProcs:
  264.                mov    cx, x1
  265.                sub    cx, x0
  266.                jge    dxNotNeg
  267.                neg    cx
  268.        dxNotNeg:
  269.                mov    dx, y1
  270.                sub    dx, y0
  271.                jge    dyNotNeg
  272.                neg    dx
  273.        dyNotNeg:
  274.                cmp    cx, dx
  275.                jg     dxGTdy
  276.                jmp    dxLEdy
  277.        dxGTdy:
  278.                mov    ax, dx
  279.                add    ax, ax
  280.                mov    c1, ax
  281.                sub    ax, cx
  282.                mov    p, ax
  283.                mov    ax, dx
  284.                sub    ax, cx
  285.                add    ax, ax
  286.                mov    c2, ax
  287.                mov    cx, x0
  288.                mov    dx, x1
  289.                cmp    cx, dx
  290.                jle    x0LEx1
  291.